#include<stdlib.h>
#include<stdio.h>

typedef struct head
{
    int n;
    struct numbers *next;
}head;

typedef struct numbers
{
    int data;
    struct numbers *next;
}numbers;

int n;

head *Create()
{

    head *h;
    numbers *p;
    numbers *t;

    p=(numbers*)malloc(sizeof(numbers*));
    h=(head*)malloc(sizeof(head*));
    scanf("%d",&n);
    int ints[30];
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&ints[n-i-1]);
    }
    
    for(int i = 0;i<n;i++)
    {
        p->data = ints[i];
        p->next=NULL;

        if (h->n == 0)
        {
            h->next=p;        
        }
        else t->next=p;
        t=p;
        p=(numbers*)malloc(sizeof(numbers*));
        h->n++;
    }
    
    return h;
}

int Show(head*h)
{   
    if (n ==0)
    {
        printf("Link list is empty\n");
        return 0;
    }
    
    numbers *p;
    p = h->next;
    for (int i = 0; i < n; i++)
    {
        printf("%d ",p->data);
        p = p->next;
    }
    printf("\n");
}

head *Delect(head*h)
{
    int m;
    numbers*p;

    p = h->next;
    scanf("%d",&m);
    if (m>n)
    {
        printf("delete fail\n");
        return h;
    }
    if (m==1)
    {
        h->next =h->next->next;
    }
    else
    {
    for (int i = 0; i < n; i++)
    {
        if (i+2 == m)
        {
            p->next = p->next->next;
            break;
        }
        p = p->next;
    }
    }
    n--;
    printf("delete OK\n");
    return h;
}

head *Insect(head *h)
{
    int m;
    numbers *t,*p;
    t=(numbers*)malloc(sizeof(numbers*));
    p = h->next;
    scanf("%d %d",&m,&t->data);

    if (m>n+1)
    {
        printf("insert fail\n");
        return h;
    }
    
    if (m == 1)
    {
        t->next=h->next;
        h->next=t;
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            if (i+2==m)
            {
                t->next=p->next;
                p->next=t;
                break;          
            }
            p=p->next;       
        }
        
    }
    printf("insert OK\n");  
    n++;
    return h;
}

int Get(head *h)
{
    int m;
    scanf("%d",&m);
    numbers *p;
    p = h->next;
    if (m>n)
    {
        printf("get fail\n");
    }
    
    for (int i = 1; i < n+1; i++)
    {
        if (i==m)
        {
            printf("%d\n",p->data);
            return 0;
        }
        p = p->next;        
    }
    
}

int main(void)
{
    int count;
    char choice[6];
    head *h;
    h = Create();
    scanf("%d",&count);
    for (int i = 0; i < count; i++)
    {
        scanf("%s",choice);
        
        if (choice[0] == 's') {Show(h);}
        else if (choice[0] == 'g') {Get(h);}
        else if (choice[0] == 'i') {h=Insect(h);}
        else if (choice[0] == 'd') {h=Delect(h);}
        
    }
    
}
